home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / mus / misc / RaveScope.lha / RaveScope / Developer / hostfuncs.s < prev   
Encoding:
Text File  |  1998-09-22  |  61.1 KB  |  1,992 lines

  1. ;-------T-------T-------T-------T-------T-------T-------T-------T-------T-------T-------T----x
  2. ;Labels (16)    Instructions (48)                               Comments (30++)
  3. ;              $VER: HostFuncs 1.2
  4. ;        Started: 980327
  5. ;       Location: Waratah.au, Malmö.se
  6. ;      Last drunk: 7 weeks ago
  7. ;    Last stoned: 4 weeks ago (M)
  8. ;           Mood: Homesick
  9. ;     Todays wishes: 1> LAG 2> Return to Sweden
  10. ;           Changed: 980328, 980329, 980330, 980331, 980403, 980412, 980413
  11. ;        Changed: 980415, 980416, 980417, 980418, 980818, 980820, 980821
  12. ;        Changed: 980827, 980907
  13.  
  14. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  15. *                                                   ...     *
  16. *    ::::::.::::::. :::::::.   .::  ::::::. .::::.  :::     *
  17. *    .::.::'.::..:: .::..::' ...`::..::..'' .::.    `'      *
  18. *    :::    :::: ::::::: `::.::::::'::::.::.::::::' :::     *
  19. *    ..................................................    *
  20. *                                                               *
  21. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  22.  
  23. ; Captain's log...
  24. ;
  25. ; 980328:0005    (038) Started this source yesterday. It's purpose is to reduce the amount of
  26. ;        code needed to adapt a player to the ravescope. It will contain easy to use
  27. ;        function calls that will take care of most of the chores with establishing a
  28. ;        connection between a ravescope host (the link between the RaveScope and the
  29. ;        player) and the RaveScope.
  30. ; 980331:0820    (038) Finally all (or at least most) routines are completed. I'll try to change
  31. ;        DeliRave into using these host functions now.
  32. ; 980403:1532    (039) Hrm, I'm still changing DeliRave and the RaveScope... A lot to be done!
  33. ;        I changed the message port names, so that they will now always be called
  34. ;        RaveScope-Host.x where x is a number starting from 0. This will make it easier
  35. ;        for the RaveScope to look for hosts. The MakeMsgPort routine will look for a
  36. ;        name that is not in use, and use that.
  37. ; 980413:1758    (041) This works quite ok with DeliRave now!
  38. ; 980413:1810    (041) Corrected bug with checking the config-id.
  39. ;        ** Made the HandleMsg routine recognize the RMSG_RAVEBUSY and RMSG_RAVEREADY
  40. ;        messages. But they produce nothing and I don't know of what use they may be.
  41. ; 980413:1855    (041) Added the rh_oPlaying flag. The host must set this when its player is
  42. ;        playing and clear it when it stops. When GrabRave is called and the RaveScope
  43. ;        is grabbed, a RMSG_PLYACTIVE msg will be sent if the host is playing.
  44. ; 980416:0315    (043) Added the rh_UpdateChans routine. It will call ms_Get4Upd to get a
  45. ;        channel header, then it may also make sure there's enough channels in there,
  46. ;        and finally call the host's routine to update these structures.
  47. ; 980417:2237    (044) The rh_GotRave routine, which is called whenever the RaveScope tells us
  48. ;        to grab it, will now check the local play-flag, and if it is set send a
  49. ;        RMSG_PLYACTIVE message to the RaveScope.
  50. ; 980418:0117    (044) Realized that this could mean sending a message that was already sent,
  51. ;        since I only had one message reserved. Changed the message routines to allocate
  52. ;        messages as they were sent, and freed as they got back. 
  53. ; 980818:1754    (050) Added the routine rh_PlyActive. Whenever a host gets a message from its
  54. ;        player that it is now playing, this routine should be called. It will inform
  55. ;        the ravescope of the new state, if the host owns the RaveScope. If not it will
  56. ;        try to grab it first.
  57. ; 980821:0023    (052) Changed some routines to return the most important value in d0, so that these
  58. ;        functions can be used from a c/++ source. May have created minor bugs as I did this.
  59. ; 980827:1717    (054) Modified the rh_OpenLibs so that it can be called several times without
  60. ;        failing or opening the same libs more than once. If a library cannot be opened, all
  61. ;        successfully opened libs will be closed before error is returned.  Also made this
  62. ;        routine and CloseLibs public. I had to do this, because Eagleplayer needs to access
  63. ;        dos.library before InitHost is called.
  64. ; 980827:1817    (054) Corrected bug, the 020+ check assumed that a6 was = sysbase. When it was not
  65. ;        it would fail on my computer. Found at that it would crash when it failed, and I'm
  66. ;        right now trying to find out why. Found minor bug while doing this, the last 2 channel
  67. ;        structures has never been freed, because to step to the next one, I increased the
  68. ;        wrong address register.
  69. ; 980827:1824    (054) It crashed because in the host I continued using the now cleared and freed
  70. ;        dosbase.
  71. ; 980827:1841    (054) A no 020 found requester will now pop up when appropriate.
  72. ; 980907:1322    (058) Added the flag rh_oFromWB. It will be set if the host starts the ravescope
  73. ;        itself, and then or:ed into the RaveScopes corresponding flag. Then it is cleared.
  74. ;        This will make the RaveScope pop up easy requesters, instead of printing any error
  75. ;        message to nil:
  76. ; 980922:0007    (065) *** Released version 1.2 on Aminet with this source (065).
  77.  
  78.         IFD    _PHXASS_
  79.         MACHINE    68020
  80.         ENDC
  81.  
  82. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  83. *
  84. *        Public functions
  85.  
  86.         XDEF    _rh_AddSig                * Add given signal to the signal mask
  87.         XDEF    _rh_AllocMsg                * Allocate a ravemessage and init it
  88.         XDEF    _rh_AllocSig                * Alloc a signal and add it to the mask
  89.         XDEF    _rh_ClrChans                * Clear the supplied channel structure
  90.         XDEF    _rh_CloseLibs                * Close all opened libraries
  91.         XDEF    _rh_FailMsg                * Reply supplied message with failurecode set
  92.         XDEF    _rh_FindRave                * Try to find the RaveScope
  93.         XDEF    _rh_FreeHost                * Free/close everything done in rh_InitHost
  94.         XDEF    _rh_FreeMsg                * Free a RaveMsg
  95.         XDEF    _rh_FreeSig                * Free a signal and remove it from the mask
  96.         XDEF    _rh_GetMsg                * Try to get a msg from the host's msgport
  97.         XDEF    _rh_GotRave                * Handle and reply the supplied GRABRAVE msg
  98.         XDEF    _rh_GrabRave                * Try to grab/launch the RaveScope
  99.         XDEF    _rh_HandleMsg                * Handle and reply the supplied ravemsg
  100.         XDEF    _rh_InitHost                * Create everything a RaveHost may need
  101.         XDEF    _rh_LoadConfig                * Load and parse the configuration file
  102.         XDEF    _rh_LostRave                * Handle and reply the supplied LEAVERAVE msg
  103.         XDEF    _rh_NukeChans                * Clear the host's channel structures
  104.         XDEF    _rh_OpenLibs                * Open dos, intuition and reqtools.library
  105.         XDEF    _rh_ParseCfg                * Parse the config
  106.         XDEF    _rh_PlyActive                * Call when your player starts playing
  107.         XDEF    _rh_ProcMsgs                * Handle all msgs currently in host's msgport
  108.         XDEF    _rh_PutMsg                * PutMsg() a RaveMsg to the RaveScope
  109.         XDEF    _rh_RaveQuit                * Handle and reply the supplied RAVEQUIT msg
  110.         XDEF    _rh_RemSig                * Remove given signal from the signal mask
  111.         XDEF    _rh_ResetCfg                * Reset the config to default values
  112.         XDEF    _rh_SignalRave                * PutMsg() to Rave AND wait IF we have it
  113.         XDEF    _rh_TellRave                * PutMsg() to Rave IF we have it
  114.         XDEF    _rh_UpdateChans                * Call when updating the channel structures
  115.         XDEF    _rh_WaitMsg                * Wait() for the specified message to return
  116.         XDEF    _rh_WaitPutMsg                * PutMsg() to Rave AND wait for reply
  117.  
  118. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  119. *
  120. *        Includes &c
  121.  
  122.         SECTION HostCode,Code
  123.  
  124.         INCDIR    include:
  125.         INCLUDE    exec/exec_lib.i
  126.         INCLUDE    exec/exec.i
  127.         INCLUDE    exec/tasks.i
  128.         INCLUDE    devices/timer_lib.i
  129.         INCLUDE    devices/timer.i
  130.         INCLUDE    dos/dos_lib.i
  131.         INCLUDE    dos/dos.i
  132.         INCLUDE    dos/dostags.i
  133.         INCLUDE graphics/graphics_lib.i
  134.         INCLUDE    graphics/gfx.i
  135.         INCLUDE    hardware/intbits.i
  136.         INCLUDE    intuition/intuition_lib.i
  137.         INCLUDE    intuition/intuition.i
  138.         INCLUDE    libraries/gadtools_lib.i
  139.         INCLUDE    libraries/gadtools.i
  140.         INCLUDE    libraries/reqtools.i
  141.         INCLUDE    libraries/reqtools_lib.i
  142.         INCDIR    ""
  143.         INCLUDE    include/monoscope.i
  144.         INCLUDE    include/ravescope.i
  145.  
  146. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  147. *
  148. *        Constants
  149.  
  150. NO:        EQU    0
  151. YES:        EQU    1
  152. MYDEBUG:    EQU    NO
  153. DEBTIME:    EQU    0
  154.  
  155. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  156. *
  157. *        Macros
  158.  
  159. PUSH:        MACRO
  160.         IFC    "\1","ALL"
  161.         movem.l    d0-a6,-(sp)
  162.         ELSE    
  163.         movem.l    \1,-(sp)
  164.         ENDC
  165.         ENDM
  166.  
  167. POP:        MACRO
  168.         IFC    "\1","ALL"
  169.         movem.l    (sp)+,d0-a6
  170.         ELSE    
  171.         movem.l    (sp)+,\1
  172.         ENDC
  173.         ENDM
  174.  
  175. CALLLVO:    MACRO
  176.             jsr    _LVO\1(a6)
  177.         ENDM
  178. JUMPLVO:    MACRO
  179.             jmp    _LVO\1(a6)
  180.         ENDM
  181.  
  182. CALLEXE:    MACRO
  183.         move.l    rh_oSysBase(a5),a6
  184.             jsr    _LVO\1(a6)
  185.         ENDM
  186. JUMPEXE:    MACRO
  187.         move.l    rh_oSysBase(a5),a6
  188.             jmp    _LVO\1(a6)
  189.         ENDM
  190.  
  191. CALLDOS:    MACRO
  192.         move.l    rh_oDOSBase(a5),a6
  193.             jsr    _LVO\1(a6)
  194.         ENDM
  195. JUMPDOS:    MACRO
  196.         move.l    rh_oDOSBase(a5),a6
  197.             jmp    _LVO\1(a6)
  198.         ENDM
  199.  
  200. CALLITN:    MACRO
  201.         move.l    rh_oIntuiBase(a5),a6
  202.             jsr    _LVO\1(a6)
  203.         ENDM
  204. JUMPITN:    MACRO
  205.         move.l    rh_oIntuiBase(a5),a6
  206.             jmp    _LVO\1(a6)
  207.         ENDM
  208.  
  209. CALLREQ:    MACRO
  210.         move.l    rh_oRTBase(a5),a6
  211.         jsr    _LVO\1(a6)
  212.         ENDM
  213. JUMPREQ:    MACRO
  214.         move.l    rh_oRTBase(a5),a6
  215.         jmp    _LVO\1(a6)
  216.         ENDM
  217.  
  218.         IFNE    MYDEBUG                    * Debug macro. Link with include:
  219.         XRef    KPrintF                    * link/debug.lib & link/amiga.lib
  220.         ENDC
  221.  
  222. SFORBID:    MACRO
  223.         PUSH    d0-d1/a0-a1/a6
  224.         CALLEXE    Forbid
  225.         POP    d0-d1/a0-a1/a6
  226.         ENDM
  227.  
  228. SPERMIT:    MACRO
  229.         PUSH    d0-d1/a0-a1/a6
  230.         CALLEXE    Permit
  231.         POP    d0-d1/a0-a1/a6
  232.         ENDM
  233.  
  234. DBUG:        MACRO
  235.         IFNE    MYDEBUG
  236.         bra    .Ok\@
  237. .Str\@:        dc.b    "HOST: ",\1,0
  238.         EVEN
  239. .Ok\@:        DBUGIT    .Str\@
  240.         ENDC
  241.         ENDM
  242.  
  243. DBUGIT:        MACRO
  244.         IFNE    MYDEBUG
  245.         PUSH    ALL
  246.         move.l    4.w,a6
  247.         CALLLVO    Forbid
  248.         lea    \1,a0
  249.         CLEARA    a1
  250.         jsr    KPrintF
  251.         CALLLVO    Permit
  252.         IFNE    DEBTIME
  253.         move.l    rh_oDOSBase(a5),d0
  254.         beq    .Skip\@
  255.         move.l    d0,a6
  256.         move.l    #DEBTIME,d1
  257.         CALLDOS    Delay
  258.         ENDC
  259. .Skip\@:    POP    ALL
  260.         ENDC
  261.         ENDM
  262.  
  263. LEASTR:        MACRO
  264.         bsr    .skip\@
  265.         dc.b    \1,0
  266.         EVEN
  267. .skip\@:    move.l    (sp)+,\2
  268.         ENDM
  269.  
  270. SETERR:        MACRO
  271.         tst.l    rh_oError(a5)                ;Error code already set?
  272.         bne    .Skip\@                    ;Yes, skip
  273.         move.l    \1,rh_oError(a5)            ;Set new error
  274. .Skip\@:
  275.         ENDM
  276.  
  277. ERRMSG:        MACRO
  278.         LEASTR    \1,a0
  279.         SETERR    a0
  280.         ENDM
  281.  
  282. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  283. *                                                *
  284. *        Add given signal (d0) to the signal mask                    *
  285. *                                                *
  286. *        void rh_AddSig(BYTE signal, struct RaveHost *host)                *
  287. *                   d0        a5                            *
  288. *                                                *
  289. *        INPUTS    d0.b    Signal number                            *
  290. *            a5.l    Pointer to the host's RaveHost structure            *
  291. *                                                *
  292. *        OUTPUTS    none                                    *
  293. *                                                *
  294. *        CHANGED    d1                                    *
  295. *                                                *
  296. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  297.  
  298. _rh_AddSig:    move.l    rh_oSigMask(a5),d1
  299.         bset.l    d0,d1
  300.         move.l    d1,rh_oSigMask(a5)
  301.         rts
  302.  
  303. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  304. *                                                *
  305. *        TASK    Allocate a ravemessage and init it                    *
  306. *                                                *
  307. *        struct RaveMsg *msg = rh_AllocMsg(struct RaveHost *host)            *
  308. *        d0                  a5                        *
  309. *                                                *
  310. *        INPUTS    a5.l    Pointer to the host's RaveHost structure            *
  311. *                                                *
  312. *        OUTPUTS    d0    Pointer to the message or NULL for failure            *
  313. *                                                *
  314. *        FLAGS    EQ    The message could not be allocated                *
  315. *            NE    The message could be allocated                    *
  316. *                                                *
  317. *        CHANGED    d0                                    *
  318. *                                                *
  319. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  320.  
  321. _rh_AllocMsg:    DBUG    "Allocating a message.\n"
  322.         PUSH    d1/a0-a1/a6
  323.         move.l    #rmsg_SIZEOF,d0
  324.         move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1
  325.         CALLEXE    AllocVec
  326.         tst.l    d0
  327.         beq    .Exit
  328.         move.l    d0,a1
  329.         move.l    a5,MN_REPLYPORT(a1)            * Init the RaveMsg
  330.         move.w    #rmsg_SIZEOF,MN_LENGTH(a1)
  331. .Exit:        POP    d1/a0-a1/a6
  332.         rts
  333.  
  334.  
  335. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  336. *                                                *
  337. *        Allocate a signal and add it to the signal mask (rh_oSigMask)            *
  338. *                                                *
  339. *        BYTE signal = rh_AllocSig(struct RaveHost *host)                *
  340. *        d0              a5                            *
  341. *                                                *
  342. *        INPUTS    a5.l    Pointer to the host's RaveHost structure            *
  343. *                                                *
  344. *        OUTPUTS    d0.b    The signal or -1 if none could be allocated            *
  345. *                                                *
  346. *        FLAGS    GE    A signal was allocated                        *
  347. *            MI    No signal could be allocated                    *
  348. *                                                *
  349. *        CHANGED    d0-d1/a0-a1/a6                                *
  350. *                                                *
  351. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  352.  
  353. _rh_AllocSig:    DBUG    "Allocating signal...\n"
  354.         moveq    #-1,d0
  355.         CALLEXE    AllocSignal                * Allocate the signal
  356.         tst.b    d0
  357.         bmi    .Error
  358.         bsr    _rh_AddSig                * Add it to the mask
  359.         bra    .Out
  360. .Error:        ERRMSG    "Couldn't allocate a signal!\n"
  361. .Out:        tst.b    d0
  362.         rts
  363.  
  364. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  365. *                                                *
  366. *        Close all opened libraries. Done automatically in rh_FreeHost            *
  367. *                                                *
  368. *        void rh_CloseLibs(struct RaveHost *host)                    *
  369. *                  a5                                *
  370. *                                                *
  371. *        INPUTS    a5.l    Pointer to the host's RaveHost structure            *
  372. *                                                *
  373. *        OUTPUTS    none                                    *
  374. *                                                *
  375. *        CHANGED    none                                    *
  376. *                                                *
  377. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  378.  
  379. _rh_CloseLibs:    PUSH    d0-d1/d7/a0-a1/a4            * Close all opened libraries
  380.         DBUG    "Closing all libraries...\n"
  381.         lea    rh_oDOSBase(a5),a4
  382.         moveq    #3-1,d7
  383. .ClLibLop:    move.l    (a4),d0
  384.         beq    .LibNotOp
  385.         movea.l    d0,a1
  386.         CALLEXE    CloseLibrary
  387. .LibNotOp:    clr.l    (a4)+
  388.         dbra    d7,.ClLibLop
  389.         POP    d0-d1/d7/a0-a1/a4
  390.         rts
  391.  
  392. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  393. *                                                *
  394. *        Fill all channel structures (pointed to by the specified header structure)    *
  395. *        with values that guarantees that they will not be used in the display.        *
  396. *                                                *
  397. *        void rh_ClrChans(struct ScopeHeader *header)                    *
  398. *                 a4                                *
  399. *                                                *
  400. *        INPUTS    a4.l    Pointer to a scopeheader structure                *
  401. *                                                *
  402. *        OUTPUTS    none                                    *
  403. *                                                *
  404. *        CHANGED    none                                    *
  405. *                                                *
  406. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  407.  
  408. _rh_ClrChans:    PUSH    d0-d1/a0
  409.         move.l    scph_oChannels(a4),d0
  410.         beq    .Exit
  411.         move.l    d0,a0
  412.         move.w    scph_oMaxChans(a4),d1
  413.         CLEAR    d0
  414.         bra    .BegInit
  415. .Init:        move.l    d0,scpc_oSampleLoop(a0)
  416.         move.l    d0,scpc_oSamplePos(a0)
  417.         move.l    d0,scpc_oSampleLeft(a0)            * No samples left to disp
  418.         move.l    d0,scpc_oLoopSize(a0)            * No loop left to disp
  419.         move.w    d0,scpc_oVolume(a0)            * No volume => don't disp
  420.         move.l    d0,scpc_oFreq(a0)            * No frequency => no update
  421.         adda.w    #scpc_SIZEOF,a0
  422. .BegInit:    dbra    d1,.Init
  423. .Exit:        POP    d0-d1/a0
  424.         rts
  425.  
  426. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  427. *                                                *
  428. *        Reply to a message that could not be handled (return RMSG_FAILURE)        *
  429. *                                                *
  430. *        void rh_FailMsg(struct Message *msg, struct RaveHost *host)            *
  431. *                a1             a5                        *
  432. *                                                *
  433. *        INPUTS    a1.l    Pointer to the message                        *
  434. *            a5.l    Pointer to the host's RaveHost structure            *
  435. *                                                *
  436. *        FLAGS    MI    Always set                            *
  437. *                                                *
  438. *        CHANGED    d0-d1/a0-a1/a6        (a6 = SysBase)                    *
  439. *                                                *
  440. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  441.  
  442. _rh_FailMsg:    DBUG    "Replying msg with RMSG_FAILURE!\n"
  443.         move.w    #RMSG_FAILURE,rmsg_oResult(a1)
  444.         CALLEXE    ReplyMsg
  445.         moveq    #-1,d0
  446.         rts
  447.  
  448. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  449. *                                                *
  450. *        Try to find the RaveScope. Caller must Permit() if the RavePort was found.    *
  451. *                                                *
  452. *        struct RaveScope *raveport = rh_FindRave(UWORD seconds, struct RaveHost *host)    *
  453. *        d0                     d0        a5            *
  454. *                                                *
  455. *        INPUTS    d0.w    Number of seconds to keep trying                *
  456. *            a5.l    Pointer to the hosts RaveHost structure                *
  457. *                                                *
  458. *        OUTPUTS    d0.l    Pointer to the RaveScope's port (RaveBase) or NULL        *
  459. *                                                *
  460. *        FLAGS    NE    Everything ok, RaveBase supplied in d0                *
  461. *            EQ    The RaveScope is not running                    *
  462. *                                                *
  463. *        CHANGED    d0-d1/a0-a1                                *
  464. *                                                *
  465. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  466.  
  467. _rh_FindRave:    DBUG    "** Entered rh_FindRave. Trying to find the RaveScope...\n"
  468.         PUSH    d2-d7/a2-a4/a6
  469.         move.w    d0,d7                    * d7 = seconds to try
  470.         bra    .Find
  471. .Wait:        CALLLVO    Permit
  472.         moveq    #50,d1                    * Wait a second
  473.         CALLDOS    Delay
  474.  
  475. .Find:        CALLEXE    Forbid
  476.         lea    rh_RSPortName,a1
  477.         DBUG    'FindPort("RaveScope")...\n'
  478.         CALLLVO    FindPort                * Try to find the RaveScope
  479.         tst.l    d0
  480.         dbne    d7,.Wait
  481.         beq    .NoRave
  482.  
  483. .Found:        DBUG    "RaveBase found. Comparing ID:s...\n"    * a4 = RaveBase, check ID:s
  484.         move.l    d0,a4                    
  485.         cmp.l    #RAVE_ID,rs_oID(a4)
  486.         beq    .RaveOk
  487.  
  488. .NoRave:    CALLLVO    Permit
  489.         DBUG    "Returning FAILURE.\n"
  490.         CLEAR    d0
  491.         bra    .Out
  492. .RaveOk:    DBUG    "Returning SUCCESS.\n"
  493.         move.l    a4,d0                    * Signal RaveBase found
  494. .Out:        POP    d2-d7/a2-a4/a6
  495.         rts
  496.  
  497. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  498. *                                                *
  499. *        TASK    Free everything opened/allocated by rh_InitHost                *
  500. *                                                *
  501. *        void rh_FreeHost(struct RaveHost *host)                        *
  502. *                 a5                                *
  503. *                                                *
  504. *        INPUTS    a5.l    Pointer to the hosts RaveHost structure.            *
  505. *                                                *
  506. *        CHANGED    d0-d1/a0-a1                                *
  507. *                                                *
  508. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  509.  
  510. _rh_FreeHost:    DBUG    "** Entered rh_FreeHost\n"
  511.         bsr    rh_FreeMsgPort                * Release RaveScope, rem msgport
  512.         bsr    rh_FreeChHds                * Free channel headers
  513.         bsr    rh_FreeCfg                * Free config
  514.         bsr    _rh_CloseLibs                * Close libs
  515.         bra    rh_FreeRHStr                * Free RaveHost struct (if allocd)
  516.         rts
  517.  
  518. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  519. *                                                *
  520. *        TASK    Free a RaveMsg                                *
  521. *                                                *
  522. *        void rh_FreeMsg(struct RaveMsg *msg, struct RaveHost *host)            *
  523. *                a1             a5                        *
  524. *                                                *
  525. *        INPUTS    a1.l    Pointer to the RaveMsg to free                    *
  526. *            a5.l    Pointer to the host's RaveHost structure            *
  527. *                                                *
  528. *        OUTPUTS    none                                    *
  529. *                                                *
  530. *        CHANGED    a1    (NULLed)                            *
  531. *                                                *
  532. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  533.  
  534. _rh_FreeMsg:    DBUG    "Freeing one of our messages.\n"
  535.         PUSH    d0-d1/a0/a6
  536.         CALLEXE    FreeVec
  537.         CLEARA    a1
  538. .Exit:        POP    d0-d1/a0/a6
  539.         rts
  540.  
  541. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  542. *                                                *
  543. *        Free a signal and remove it from the signal mask (rh_oSigMask)            *
  544. *                                                *
  545. *        void rh_FreeSig(BYTE *signal, struct RaveHost *host)                *
  546. *                a0          a5                        *
  547. *                                                *
  548. *        INPUTS    a0.l    Pointer to the signal number                    *
  549. *            a5.l    Pointer to the host's RaveHost structure            *
  550. *                                                *
  551. *        OUTPUTS    none                                    *
  552. *                                                *
  553. *        CHANGED    d0-d1/a0-a1/a6                                *
  554. *                                                *
  555. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  556.  
  557. _rh_FreeSig:    DBUG    "Freeing the signal...\n"
  558.         move.b    (a0),d0
  559.         bmi    .Exit
  560.         st    (a0)
  561.         bsr    _rh_RemSig
  562.         JUMPEXE    FreeSignal
  563. .Exit:        rts
  564.  
  565. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  566. *                                                *
  567. *        Try to get a message from the host's messageport.                *
  568. *                                                *
  569. *        struct Message *msg, UWORD class = rh_GetMsg(struct RaveHost *host)        *
  570. *        d0             d1                 a5                    *
  571. *                                                *
  572. *        INPUTS    a5.l    Pointer to the hosts RaveHost structure                *
  573. *                                                *
  574. *        OUTPUTS    d0.l    Pointer to the message or NULL if none                *
  575. *            d1.w    The recieved message's class                    *
  576. *                                                *
  577. *        FLAGS    NE    Got a message                            *
  578. *            EQ    Did not get a message                        *
  579. *                                                *
  580. *        CHANGED    d0-d1/a0-a1/a6        (a6 = SysBase)                    *
  581. *                                                *
  582. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  583.  
  584. _rh_GetMsg:    move.l    a5,a0
  585.         CALLEXE    GetMsg                    * Get the message
  586.         tst.l    d0                    * Any?
  587.         bne    .GotMsg                    * Yes
  588.         DBUG    "The message flow has stopped.\n"    * No, WaitPort() again.
  589.         CLEAR    d0
  590.         bra    .Out
  591. .GotMsg:    move.l    d0,a1
  592.         move.w    rmsg_oType(a1),d1
  593.         IFNE    MYDEBUG
  594.         move.w    d1,d0
  595.         SFORBID
  596.         DBUG    "Got "
  597.         bsr    _rh_IdentMsg
  598.         DBUGIT    (a0)
  599.         LEASTR    "\n",a0
  600.         DBUGIT    (a0)
  601.         SPERMIT
  602.         ENDC
  603.         move.l    a1,d0
  604. .Out:        rts
  605.  
  606.  
  607. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  608. *                                                *
  609. *        Handle the RMSG_GRABRAVE message and reply it with the success code set.    *
  610. *                                                *
  611. *        void rh_GotRave(struct Message *msg, struct RaveHost *host)            *
  612. *                a1             a5                        *
  613. *                                                *
  614. *        INPUTS    a1.l    Pointer to the message                        *
  615. *            a5.l    Pointer to the host's RaveHost structure            *
  616. *                                                *
  617. *        FLAGS    GT    Always set                            *
  618. *                                                *
  619. *        CHANGED    d0-d1/a0-a1/a6        (a6 = SysBase)                    *
  620. *                                                *
  621. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  622.  
  623. _rh_GotRave:    DBUG    "Grabbing the RaveScope.\n"
  624.         DBUG    "Replying to RMSG_GRABRAVE message.\n"
  625.         move.l    rmsg_oData(a1),rh_oRaveBase(a5)        * Store supplied RaveBase
  626.         move.w    #RMSG_SUCCESS,rmsg_oResult(a1)
  627.         CALLEXE    ReplyMsg
  628.         tst.b    rh_oPlaying(a5)                * Is our player playing?
  629.         beq    .NoPlay                    * No
  630.         move.w    #RMSG_PLYACTIVE,d0            * Yes, inform the RaveScope
  631.         bsr    _rh_PutMsg
  632.         IFNE    MYDEBUG
  633.         moveq    #1,d0
  634.         rts
  635.         ENDC
  636.  
  637. .NoPlay:    DBUG    "rh_oPlaying is CLEARED.\n"
  638.         moveq    #1,d0
  639.         rts
  640.  
  641.  
  642. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  643. *                                                *
  644. *        TASK    Try to grab the RaveScope. Launch it if it is not present. Ask for its    *
  645. *            path (via reqtools) if current path (in prefs) is not known/invalid.    *
  646. *                                                *
  647. *        LONG success = rh_GrabRave(struct RaveHost *host)                *
  648. *        d0               a5                            *
  649. *                                                *
  650. *        INPUTS    a5.l    Pointer to the hosts RaveHost structure                *
  651. *                                                *
  652. *        OUTPUTS    d0.l    -1, 1 or 0, corresponds to flags below.                *
  653. *            a5.l    Pointer to the RaveHost structure                *
  654. *                                                *
  655. *        FLAGS    MI    The RaveScope could not be grabbed.                *
  656. *            GT    Everything fine, the RaveScope is grabbed.            *
  657. *            EQ    Serious error, host should quit if possible            *
  658. *                                                *
  659. *        CHANGED    d0-d1/a0-a1                                *
  660. *                                                *
  661. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  662.  
  663. _rh_GrabRave:    PUSH    d2-d7/a2-a4/a6
  664.         DBUG    "** Entered rh_GrabRave.\n"
  665.         tst.l    a5
  666.         beq    .Error
  667.         tst.l    rh_oRaveBase(a5)            * RaveScope not already grabbed?
  668.         bne    .Grabbed
  669.  
  670.         CLEAR    d0
  671.         bsr    _rh_FindRave                * RaveScope present?
  672.         bne    .RaveOk                    * Yes, wait for it to grab us
  673.  
  674.         lea    ([rh_oCfgPtr,a5],hcfg_oRaveName),a4    * a4 = current RaveScope path
  675.         tst.b    (a4)
  676.         bne    .NameOk
  677.  
  678. .ReqName:    DBUG    "Ravename not present/valid. Allocating filerequester.\n"
  679.         move.l    #RT_FILEREQ,d0
  680.         CLEARA    a0
  681.         CALLREQ    rtAllocRequestA
  682.         move.l    d0,d5                    * d5 = RT filerequest
  683.         beq    .Error
  684.  
  685.         DBUG    "Calling filerequester.\n"
  686.         movea.l    d5,a1                    * Ask for file
  687.         lea    rh_FileName,a2
  688.         lea    rh_AskFileTxt,a3
  689.         lea    rh_ReqTags,a0
  690.         CALLLVO    rtFileRequestA
  691.         tst.l    d0                    * Any file selected?
  692.         bne    .ReqOk
  693.         bsr    .FreeReq
  694.         bra    .Fail
  695.  
  696. .ReqOk:        DBUG    "AddPart()ing path.\n"
  697.         move.l    d5,a0
  698.         move.l    rtfi_Dir(a0),d2                * Add the path
  699.         move.l    a4,d1
  700.         clr.b    (a4)
  701.         move.l    #500-1,d3                * Size of ravename buffer
  702.         CALLDOS    AddPart
  703.         tst.l    d0                    * Buffer overflowed?
  704.         bne    .PathOk
  705.         bsr    .FreeReq
  706.         bra    .Error
  707.  
  708. .PathOk:    DBUG    "AddPart()ing filename.\n"
  709.         move.l    #rh_FileName,d2                * Add the filename
  710.         move.l    a4,d1                    * To the path in the ravename
  711.         CALLLVO    AddPart
  712.         move.l    d0,d2
  713.         bsr    .FreeReq
  714.         tst.l    d2                    * Buffer overflowed?
  715.         beq    .Error
  716.  
  717. .NameOk:    DBUG    "Ravename obtained : "
  718.         DBUGIT    (a4)
  719.         IFNE    MYDEBUG
  720.         LEASTR    "\n",a3
  721.         DBUGIT    (a3)
  722.         ENDC
  723.  
  724.         DBUG    "Trying to Lock() the exe.\n"        * Make sure name is ok
  725.         move.l    a4,d1
  726.         move.l    #ACCESS_READ,d2
  727.         CALLDOS    Lock
  728.         move.l    d0,d1
  729.         beq    .ReqName
  730.         CALLLVO    UnLock
  731.  
  732.         DBUG    "Trying to start the RaveScope...\n"    * Open NIL:s
  733.         DBUG    "Opening NIL:s\n"
  734.         bsr    .OpenNIL
  735.         move.l    d0,rh_NilInput+4
  736.         beq    .Error
  737.         bsr    .OpenNIL
  738.         move.l    d0,rh_NilOutput+4
  739.         bne    .NILsOk
  740.         bsr    .CloseNILs
  741.         bra    .Error
  742.  
  743. .NILsOk:    DBUG    "Calling SystemTagList()\n"        * Execute EagleRave
  744.         st    rh_oFromWB(a5)
  745.         move.l    a4,d1
  746.         move.l    #rh_ExeTags,d2
  747.         CALLDOS    SystemTagList
  748.  
  749.         IFNE    MYDEBUG                    * Show it's result-code
  750.         bra    .DoDebug
  751. .DebugMsg:    dc.b    "HOST: SystemTagList() returned : $"
  752. .DebugNum:    dc.b    "        .\n",0
  753.         EVEN
  754. .DoDebug:    lea    .DebugNum,a1
  755.         bsr    rh_D0toASCII
  756.         DBUGIT    .DebugMsg
  757.         ENDC
  758.  
  759.         not.l    d0                    * Could the RaveScope be started?
  760.         bne    .Executed                * Yes
  761.         bsr    .CloseNILs                * No, close NIL filehandles
  762.         bra    .Error
  763.  
  764. .Executed:    DBUG    "Waiting for the RavePort to appear.\n"    * Wait max 20 seconds for it
  765.         moveq    #20,d0                    
  766.         bsr    _rh_FindRave                * This routine will Forbid()
  767.         beq    .Fail                    * unless it fails (EQ)
  768.  
  769. .RaveOk:    DBUG    "The RavePort has been found OK.\n"
  770.         move.l    d0,a0                    * Now or this wb flag into the RaveScope
  771.         move.b    rs_oFromWB(a0),d0            * and clear it
  772.         or.b    rh_oFromWB(a5),d0
  773.         move.b    d0,rs_oFromWB(a0)
  774.         clr.b    rh_oFromWB(a5)
  775.         CALLEXE    Permit
  776.  
  777.         move.w    #RMSG_NEWHOST,d0
  778.         bsr    _rh_WaitPutMsg
  779.         bmi    .NoGrab                    * RaveScope did not grab us
  780.         beq    .Fail                    * RaveScope wants to quit
  781.  
  782. .Grabbed:    DBUG    "The RaveScope has grabbed us.\n"    * We now have the RaveScope...
  783.         moveq    #1,d0
  784. .Out:        POP    d2-d7/a2-a4/a6
  785.         rts
  786.  
  787. .Fail:        DBUG    "Giving up. Returning ERROR.\n"        * Ravescope not found, display
  788.         CLEARA    a0                    * error message and exit.
  789.         lea    rh_RaveFailReq,a1
  790.         CLEARA    a2
  791.         CLEARA    a3
  792.         CALLITN    EasyRequestArgs
  793. .NoGrab:    moveq    #-1,d0                    * Signal OK, but no grab
  794.         bra    .Out
  795.  
  796. .Error:        DBUG    "Serious error occured!\n"
  797.         CLEAR    d0                    * Signal error
  798.         bra    .Out
  799.  
  800. .OpenNIL:    move.l    #rh_NilName,d1                * Open NIL file handle
  801.         move.l    #MODE_NEWFILE,d2
  802.         JUMPDOS    Open
  803.  
  804. .CloseNILs:    move.l    rh_NilInput+4,d1            * Close NIL: file handles
  805.         beq    .SkipNIL1
  806.         clr.l    rh_NilInput+4
  807.         CALLDOS    Close
  808. .SkipNIL1:    move.l    rh_NilOutput+4,d1
  809.         beq    .Out
  810.         clr.l    rh_NilOutput+4
  811.         JUMPDOS    Close
  812.  
  813. .FreeReq:    tst.l    d5                    * RTFileRequest struct alloced?
  814.         beq    .NoReq
  815.         movea.l    d5,a1
  816.         DBUG    "Closing filerequester.\n"
  817.         CALLREQ    rtFreeRequest
  818.         DBUG    "Filerequester closed.\n"
  819. .NoReq:        rts
  820.  
  821.         IFNE    MYDEBUG
  822. rh_D0toASCII:    PUSH    d1-d2/a1                * Convert d0.l to ASCII, store
  823.         moveq    #8-1,d2                    * the result in (a1)+
  824. .Loop:        rol.l    #4,d0
  825.         move.b    d0,d1
  826.         andi.b    #$F,d1
  827.         cmpi.b    #9,d1
  828.         bgt    .Letter
  829.         add.b    #'0'-('A'-$A),d1
  830. .Letter:    add.b    #'A'-$A,d1
  831.         move.b    d1,(a1)+
  832.         dbra    d2,.Loop
  833.         POP    d1-d2/a1
  834.         rts
  835.         ENDC
  836.  
  837. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  838. *                                                *
  839. *        Handle & reply to any kind of message that has arrived to the host's msgport    *
  840. *                                                *
  841. *        void rh_HandleMsg(UWORD class, struct Message *msg, struct RaveHost *host)    *
  842. *                  d0           a1            a5                *
  843. *                                                *
  844. *        INPUTS    d0.w    The recieved message's class                    *
  845. *            a1.l    Pointer to the message                        *
  846. *            a5.l    Pointer to the host's RaveHost structure            *
  847. *                                                *
  848. *        OUTPUTS    none                                    *
  849. *                                                *
  850. *        FLAGS    GT    We have the RaveScope                        *
  851. *            MI    We do not have the RaveScope                    *
  852. *            EQ    The RaveScope is quitting (it has been released)        *
  853. *                                                *
  854. *        CHANGED    none                                    *
  855. *                                                *
  856. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  857.  
  858. _rh_HandleMsg:    DBUG    "** Entered rh_HandleMsg.\n"
  859.         PUSH    d0-d1/a0-a1/a6
  860.         btst    #RMSGB_FROMRAVE,d0
  861.         bne    .FromRave
  862.         DBUG    "The message is from us! Returning\n"
  863.         bra    .Exit
  864. .FromRave:    pea    .Out                    * Return here
  865.         cmp.w    #RMSG_RAVEQUIT,d0
  866.         beq    _rh_RaveQuit
  867. .NoQuit:    cmp.w    #RMSG_LEAVERAVE,d0
  868.         beq    _rh_LostRave
  869.         cmp.w    #RMSG_GRABRAVE,d0
  870.         beq    _rh_GotRave
  871.  
  872.         cmp.w    #RMSG_RAVEREADY,d0            * The RAVEREADY and RAVEBUSY
  873.         beq    .HReady                    * msgs currently don't produce
  874.         cmp.w    #RMSG_RAVEBUSY,d0            * anything more than forcing
  875.         bne    .AlienMsg                * the host out from a Wait()
  876.         DBUG    "Got RMSG_RAVEBUSY.\n"
  877.         IFNE    MYDEBUG
  878.         bra    .MsgOk
  879.         ENDC
  880. .HReady:    DBUG    "Got RMSG_RAVEREADY.\n"
  881. .MsgOk:        move.w    #RMSG_SUCCESS,rmsg_oResult(a1)
  882.         CALLEXE    ReplyMsg
  883.         moveq    #1,d0                    * We have the ravescope
  884.         rts    
  885.  
  886. .AlienMsg:    addq.l    #4,sp                    * This should never happen
  887.         bsr    _rh_FailMsg
  888. .Exit:        tst.l    rh_oRaveBase(a5)            * Return MI if we don't have
  889.         seq    d0                    * the RaveScope, GT if we do.
  890.         addq.b    #1,d0
  891. .Out:        POP    d0-d1/a0-a1/a6
  892.         rts
  893.  
  894. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  895. *                                                *
  896. *        TASK    Create everything a RaveHost may need, try to load preferences, and    *
  897. *            launch/grab the RaveScope if the popup flag is set.            *
  898. *                                                *
  899. *        RaveHost *h = rh_InitHost(STRPTR name, STRPTR cfg, TagItem *tags, RaveHost *h)    *
  900. *        d0              a0           a1       a2          a5        *
  901. *                                                *
  902. *        INPUTS    a0.l    Name of this host's player, e.g DeliTracker            *
  903. *            a1.l    Complete path & name to the host's configuration file, or NULL    *
  904. *            a2.l    Pointer to a list of tags or NULL (No tags defined yet!)    *
  905. *            a5.l    Pointer to the hosts RaveHost structure, NULL for allocaction    *
  906. *                                                *
  907. *        OUTPUTS    d0.l    Pointer to the RaveHost structure or NULL for failure        *
  908. *            a5.l    Pointer to the RaveHost structure if successful            *
  909. *                                                *
  910. *        FLAGS    NE    Everything went ok                        *
  911. *            EQ    Serious error, host must quit.                    *
  912. *                                                *
  913. *        CHANGED    d0-d1/a0-a1(/a5)    a5 only changed if originally NULL        *
  914. *                                                *
  915. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  916.  
  917. _rh_InitHost:    PUSH    d2-d7/a2-a4/a6
  918.         DBUG    "** Entered rh_InitHost.\n"
  919.  
  920.         PUSH    a0-a1
  921.         move.l    a5,d2
  922.         seq    d2                    * Alloc mem for RaveHost struct?
  923.         bne    .StrOk                    * d2 = no, and don't free later
  924.  
  925.         DBUG    "Allocating mem for Host struct.\n"    * Alloc mem for the RaveHost
  926.         move.l    4,a6                    * structure if requested
  927.         move.l    #rh_SIZEOF,d0
  928.         move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1
  929.         CALLLVO    AllocVec
  930.         move.l    d0,a5
  931.  
  932. .StrOk:        POP    a0-a1
  933.         move.l    a5,d1                    * RaveHost struct exists?
  934.         beq    .Error
  935.  
  936.         move.b    d2,rh_oFreeRHStr(a5)            * Store ravehost free flag
  937.         move.l    #RAVE_ID,rh_oID(a5)            * Set ID
  938.         move.l    a0,rh_oHostName(a5)            * Must have a name
  939.         beq    .Error
  940.         move.l    a1,rh_oCfgName(a5)            * Set configname
  941.         clr.l    rh_oCfgSize(a5)                * and default size
  942.  
  943.         bsr    _rh_OpenLibs                * Open all libs
  944.         beq    .Error
  945.         DBUG    "Libraries opened OK.\n"
  946.  
  947.         bsr    rh_Check020                * Make sure 020+ is present
  948.         beq    .Error
  949.         DBUG    "020+ found OK.\n"
  950.  
  951.         CLEARA    a1                    * Get & store a pointer to
  952.         CALLEXE    FindTask                * this task
  953.         move.l    d0,rh_oThisTask(a5)
  954.  
  955.         bsr    _rh_NukeChans                * Init channel headers
  956.  
  957.         bsr    rh_MakeMsgPort                * Create the message port
  958.         beq    .Error
  959.         DBUG    "Messageport created OK.\n"
  960.  
  961.         move.l    rh_oCfgName(a5),a0
  962.         bsr    _rh_LoadConfig                * Try to load the config
  963.         beq    .Error
  964.         DBUG    "Config read/inited OK.\n"
  965.  
  966.         tst.b    rh_oPopup(a5)                * Popup?
  967.         beq    .NoPop
  968.         bsr    _rh_GrabRave
  969.         beq    .Error
  970.         bgt    .Grabbed
  971.  
  972. .NoPop:        DBUG    "Host inited ok! Scope not grabbed.\n\n"
  973.         move.l    a5,d0
  974.         bra    .Out
  975. .Grabbed:    DBUG    "Host inited ok! Scope has been grabbed.\n\n"
  976.         move.l    a5,d0
  977.         bra    .Out
  978. .Error:        DBUG    "Host could not be inited! Returning ERROR.\n\n"
  979.         bsr    _rh_FreeHost
  980.         CLEAR    d0
  981. .Out:        POP    d2-d7/a2-a4/a6
  982.         rts
  983.  
  984. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  985. *                                                *
  986. *        Load and parse the configuration file                        *
  987. *                                                *
  988. *        LONG success = rh_LoadConfig(UBYTE *cfgname, struct RaveHost *host)        *
  989. *        d0                 a0             a5                    *
  990. *                                                *
  991. *        INPUTS    a0.l    Full path with filename to the config to load            *
  992. *            a5.l    Pointer to the host's RaveHost structure            *
  993. *                                                *
  994. *        OUTPUTS    d0.l    1, -1 or 0. Corresponds to flags below.                *
  995. *                                                *
  996. *        FLAGS    GT    Everything went fine                        *
  997. *            MI    The config could not be found/loaded                *
  998. *            EQ    Serious error (mem related) host must quit            *
  999. *                                                *
  1000. *        CHANGED    d0-d1/a0-a1/a6                                *
  1001. *                                                *
  1002. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1003.  
  1004. _rh_LoadConfig:    DBUG    "** Entered rh_LoadConfig.\n"
  1005.         PUSH    d2-d7
  1006.         CLEAR    d4                    * d4 = lock
  1007.         CLEAR    d5                    * d5 = fib
  1008.         CLEAR    d6                    * d6 = filehd
  1009.         moveq    #-1,d7                    * d7 = config not loaded yet
  1010.         move.l    a0,d1                    * Get config-name
  1011.         beq    .NoCfg
  1012.         move.l    #ACCESS_READ,d2
  1013.         DBUG    "Trying to lock config.\n"
  1014.         CALLDOS    Lock
  1015.         move.l    d0,d4
  1016.         beq    .NoCfg
  1017.  
  1018.         DBUG    "Found. Allocating mem for FIB.\n"    * Alloc mem for FIB
  1019.         move.l    #fib_SIZEOF,d0
  1020.         move.l    #MEMF_CLEAR,d1
  1021.         CALLEXE    AllocVec
  1022.         move.l    d0,d5
  1023.         beq    .Error
  1024.  
  1025.         DBUG    "Ok. Examining config.\n"        * Get size of config
  1026.         move.l    d4,d1
  1027.         move.l    d5,d2
  1028.         CALLDOS    Examine
  1029.         tst.l    d0
  1030.         beq    .NoCfg
  1031.         move.l    d5,a0
  1032.         move.l    fib_Size(a0),rh_oCfgSize(a5)
  1033.         moveq    #1,d7                    * Cfg will probably load
  1034.  
  1035. .NoCfg:        DBUG    "Allocating mem for config.\n"        * Alloc mem for config
  1036.         move.l    rh_oCfgSize(a5),d0
  1037.         bne    .SizeOk
  1038.         move.l    #hcfg_SIZEOF,d0
  1039.         move.l    d0,rh_oCfgSize(a5)
  1040. .SizeOk:    move.l    #MEMF_CLEAR,d1
  1041.         CALLEXE    AllocVec
  1042.         move.l    d0,rh_oCfgPtr(a5)
  1043.         beq    .Error
  1044.  
  1045.         tst.l    d7                    * Config exists?
  1046.         bmi    .Reset                    * No, reset to default values
  1047.         moveq    #-1,d7                    * Assume failure
  1048.         DBUG    "Trying to open config...\n"
  1049.         move.l    d4,d1
  1050.         CALLDOS    OpenFromLock
  1051.         move.l    d0,d6
  1052.         beq    .Reset
  1053.         CLEAR    d4                    * Can't use lock anymore now!
  1054.  
  1055.         DBUG    "Ok. Reading it.\n"
  1056.         move.l    d0,d1                    * Read the config
  1057.         move.l    rh_oCfgPtr(a5),d2
  1058.         move.l    rh_oCfgSize(a5),d3
  1059.         CALLLVO Read
  1060.         not.l    d0
  1061.         beq    .Reset
  1062.  
  1063.         move.l    ([rh_oCfgPtr,a5],hcfg_oID),d0        * Config-ID correct?
  1064.         cmp.l    rh_oID(a5),d0
  1065.         bne    .WrongID
  1066.         moveq    #1,d7                    * Set definite success
  1067.         bra    .Parse
  1068.  
  1069. .WrongID:    DBUG    "OBSOLETE CONFIG FILE!\n"
  1070. .Reset:        bsr    _rh_ResetCfg
  1071.  
  1072. .Parse:        bsr    _rh_ParseCfg
  1073.         bsr    .Close                    * Close fib/lock/hd & ret OK
  1074.         move.l    d7,d0
  1075. .Out:        POP    d2-d7
  1076.         rts
  1077.  
  1078. .Error:        bsr    .Close                    * Close fib/lock/hd & ret ERR
  1079.         CLEAR    d0
  1080.         bra    .Out
  1081.  
  1082. .Close:        move.l    d6,d1                    * Close config-file?
  1083.         beq    .NoCl
  1084.         DBUG    "Closing config-file.\n"
  1085.         CALLDOS    Close
  1086.  
  1087. .NoCl:        tst.l    d5                    * Free FIB?
  1088.         beq    .NoFr
  1089.         DBUG    "Freeing FIB.\n"
  1090.         move.l    d5,a1
  1091.         CALLEXE    FreeVec
  1092.  
  1093. .NoFr:        move.l    d4,d1                    * Unlock config?
  1094.         beq    .NoUl
  1095.         DBUG    "Unlocking config.\n"
  1096.         JUMPDOS    UnLock
  1097. .NoUl:        rts
  1098.  
  1099.  
  1100. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1101. *                                                *
  1102. *        Handle the RMSG_LEAVERAVE message and reply it with the success code set.    *
  1103. *                                                *
  1104. *        void rh_LostRave(struct Message *msg, struct RaveHost *host)            *
  1105. *                 a1              a5                    *
  1106. *                                                *
  1107. *        INPUTS    a1.l    Pointer to the message                        *
  1108. *            a5.l    Pointer to the host's RaveHost structure            *
  1109. *                                                *
  1110. *        FLAGS    MI    Always set                            *
  1111. *                                                *
  1112. *        CHANGED    d0-d1/a0-a1/a6        (a6 = SysBase)                    *
  1113. *                                                *
  1114. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1115.  
  1116. _rh_LostRave:    DBUG    "Releasing the RaveScope.\n"
  1117.         DBUG    "Replying to RMSG_LEAVERAVE message.\n"
  1118.         clr.l    rh_oRaveBase(a5)            * Release it
  1119.         move.w    #RMSG_SUCCESS,rmsg_oResult(a1)        * And return success
  1120.         CALLEXE    ReplyMsg
  1121.         moveq    #-1,d0
  1122.         rts
  1123.  
  1124. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1125. *                                                *
  1126. *        Clear all the host's channel structures, and mark them as containing invalid    *
  1127. *        data. The RaveScope will not even attempt to display them until you have    *
  1128. *        updated them.                                    *
  1129. *                                                *
  1130. *        void rh_NukeChans(struct RaveHost *host)                    *
  1131. *                  a5                                *
  1132. *                                                *
  1133. *        INPUTS    a5.l    Pointer to the host's RaveHost structure            *
  1134. *                                                *
  1135. *        OUTPUTS    none                                    *
  1136. *                                                *
  1137. *        CHANGED    none                                    *
  1138. *                                                *
  1139. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1140.  
  1141. _rh_NukeChans:    PUSH    d7/a4
  1142.         lea    rh_oChanHdrs(a5),a4            * a4 = ptr to chan headers
  1143.         moveq    #3-1,d7                    * Reset all 3 of them
  1144.  
  1145. .Reset:        bset.b    #SCPHB_INVALID,scph_oFlags(a4)        * Not yet valid for display
  1146.         clr.l    scph_oFreshness(a4)            * Reset freshness
  1147.         clr.w    scph_oNumChans(a4)            * No channels to display
  1148.         bsr    _rh_ClrChans
  1149.         adda.w    #scph_SIZEOF,a4                * Go to next ScopeHeader
  1150.         dbra    d7,.Reset
  1151.         POP    d7/a4
  1152.         rts
  1153.  
  1154. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1155. *                                                *
  1156. *        Open dos.library, intuition.library and reqtools.library and set SysBase.    *
  1157. *        Done automatically in rh_InitHost.                        *
  1158. *                                                *
  1159. *        BOOL success = rh_OpenLibs(struct RaveHost *host)                *
  1160. *        d0               a5                            *
  1161. *                                                *
  1162. *        INPUTS    a5.l    Pointer to the host's RaveHost structure            *
  1163. *                                                *
  1164. *        OUTPUTS    d0.l    0 for failure                            *
  1165. *                                                *
  1166. *        FLAGS    EQ    All libraries could not be opened                *
  1167. *            NE    All libraries was opened ok                    *
  1168. *                                                *
  1169. *        CHANGED    d0                                    *
  1170. *                                                *
  1171. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1172.  
  1173. _rh_OpenLibs:    PUSH    d1/d7/a0-a4
  1174.         DBUG    "Opening libraries...\n"
  1175.         move.l    4.w,rh_oSysBase(a5)            * Execbase to fastmem
  1176.         lea    .LP,a3                
  1177.         lea    rh_oDOSBase(a5),a4
  1178.         moveq    #3-1,d7                    * Open dos,int,reqt
  1179.  
  1180. .OpenLib:    movem.w    (a3)+,d0/d1                * d0=version#,d1=nameofs
  1181.         lea    .LP(pc,d1),a2                * a2=library name
  1182.         move.l    a2,a1
  1183.         tst.l    (a4)+                    * Library not already open?
  1184.         bne    .SkipLib
  1185.  
  1186.         CALLEXE    OpenLibrary                * Open it
  1187.         move.l    d0,-4(a4)                * Store
  1188. .SkipLib:    dbeq    d7,.OpenLib
  1189.         bne    .Done
  1190.         bsr    _rh_CloseLibs                * Close any opened lib
  1191.         bsr    rh_ErrOpenA2                * Display error message
  1192. .Done:        POP    d1/d7/a0-a4
  1193.         rts
  1194.  
  1195. .LP:        dc.w    39,.DN-.LP,39,.IN-.LP            * Library name pointers and
  1196.         dc.w    REQTOOLSVERSION,.RN-.LP            * required version numbers
  1197. .DN:        dc.b    "dos.library",0
  1198. .IN:        dc.b    "intuition.library",0
  1199. .RN:        dc.b    "reqtools.library",0
  1200.         EVEN
  1201.  
  1202. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1203. *                                                *
  1204. *        Parse the config, so the variables in the RaveHost structure reflects it    *
  1205. *                                                *
  1206. *        void rh_ParseConfig(struct RaveHost *host)                    *
  1207. *                    a5                                *
  1208. *                                                *
  1209. *        INPUTS    a5.l    Pointer to the host's RaveHost structure            *
  1210. *                                                *
  1211. *        CHANGED    d0-d1/a0-a1                                *
  1212. *                                                *
  1213. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1214.  
  1215. _rh_ParseCfg:    DBUG    "Parsing config.\n"
  1216.         move.l    rh_oCfgPtr(a5),a0
  1217.         move.l    hcfg_oPopup(a0),rh_oPopup(a5)        * Set popup flags from config
  1218.         rts
  1219.  
  1220. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1221. *                                                *
  1222. *        Call this when the host starts playing. It will set the host's play-flag and    *
  1223. *        notify the RaveScope of this. If the host does not have the RaveScope, it will  *
  1224. *        try to grab it.                                    *
  1225. *                                                *
  1226. *        void rh_PlyActive(struct RaveHost *host)                    *
  1227. *                  a5                                *
  1228. *                                                *
  1229. *        INPUTS    a5.l    Pointer to the host's RaveHost structure            *
  1230. *                                                *
  1231. *        OUTPUTS    none                                    *
  1232. *                                                *
  1233. *        CHANGED    d0-d1/a0-a1/a6                                *
  1234. *                                                *
  1235. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1236.  
  1237. _rh_PlyActive:    DBUG    "** Entered rh_PlyActive\n"
  1238.         move.w    #RMSG_PLYACTIVE,d0
  1239.         st    rh_oPlaying(a5)                * We're playing now
  1240.         tst.l    rh_oRaveBase(a5)            * Do we have the RaveScope?
  1241.         bne    _rh_WaitPutMsg                * Yes, send message
  1242.  
  1243.         DBUG    "Trying to grab RaveScope by force\n"    * No, try to grab it
  1244.         move.w    #RMSG_NEWHOST,d0
  1245.         jsr    _rh_WaitPutMsg
  1246.         ble    .Out                    * Could not be grabbed
  1247.  
  1248.         move.w    #RMSG_PLYACTIVE,d0            * Tell the RaveScope (if we
  1249.         jmp    _rh_SignalRave                * still have it) we're playing
  1250. .Out:        rts
  1251.  
  1252. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1253. *                                                *
  1254. *        Handle & reply to all messages that has arrived to the host's msgport.        *
  1255. *                                                *
  1256. *        LONG result = rh_ProcMsgs(struct RaveHost *host)                *
  1257. *        d0              a5                            *
  1258. *                                                *
  1259. *        INPUTS    a5.l    Pointer to the host's RaveHost structure            *
  1260. *                                                *
  1261. *        OUTPUTS    d0.l    1, -1 or 0. Corresponds to flags below.                *
  1262. *                                                *
  1263. *        FLAGS    GT    We have the RaveScope                        *
  1264. *            MI    We do not have the RaveScope                    *
  1265. *            EQ    The RaveScope is quitting (it has been released)        *
  1266. *                                                *
  1267. *        CHANGED    d0                                    *
  1268. *                                                *
  1269. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1270.  
  1271. _rh_ProcMsgs:    DBUG    "** Entered rh_ProcMsgs.\n"
  1272.         PUSH    d1/a0-a1/a6
  1273. .GetMsg:    bsr    _rh_GetMsg                * Get a message
  1274.         beq    .Exit                    * No more!
  1275.         move.l    d0,a1
  1276.         move.w    d1,d0
  1277.         bsr    _rh_HandleMsg                * Handle the message
  1278.         bne    .GetMsg                    * No quit-message => check next
  1279.         CLEAR    d0
  1280. .Out:    
  1281.         IFNE    MYDEBUG
  1282.         DBUG    "-> Leaving rh_ProcMsgs.\n"
  1283.         tst.l    d0
  1284.         ENDC
  1285.         POP    d1/a0-a1/a6                * Got quit-message, exit EQ
  1286.         rts
  1287. .Exit:        tst.l    rh_oRaveBase(a5)            * Return MI if we don't have
  1288.         seq    d0                    * the RaveScope, GT if we do.
  1289.         extb.l    d0
  1290.         bmi    .Out
  1291.         moveq    #1,d0
  1292.         bra    .Out
  1293.  
  1294. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1295. *                                                *
  1296. *        TASK    PutMsg() a RaveMsg to the RaveScope.                    *
  1297. *                                                *
  1298. *        BOOL success = rh_PutMsg(UWORD msgclass, struct RaveHost *host)            *
  1299. *        d0             d0         a5                    *
  1300. *                                                *
  1301. *        INPUTS    d0.w    The message class, for example RMSG_HOSTQUIT            *
  1302. *            a5.l    Pointer to the host's RaveHost structure            *
  1303. *                                                *
  1304. *        OUTPUTS    d0.w    TRUE or FALSE, corresponds to flags below.            *
  1305. *                                                *
  1306. *        FLAGS    EQ    The message could not be sent                    *
  1307. *            NE    The message was sent                        *
  1308. *                                                *
  1309. *        CHANGED    d0/a6                                    *
  1310. *                                                *
  1311. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1312.  
  1313. _rh_PutMsg:    PUSH    d0-d3/a0-a1
  1314.         move.w    d0,d2                    * Remember the message class
  1315.         CLEAR    d3                    * d3 = we have not called Forbid()
  1316.         move.l    rh_oRaveBase(a5),d0            * Do we have the RaveScope?
  1317.         bne    .RaveOk                    * Yes
  1318.         CLEAR    d0                    * No, try to find it
  1319.         bsr    _rh_FindRave                * (wait 0 secs)
  1320.         beq    .Out                    * Could not be found.
  1321.         moveq    #1,d3                    * Found, remember to Permit()
  1322.  
  1323. .RaveOk:    cmp.w    #RMSG_HOSTQUIT,d2            * Send RMSG_HOSTQUIT?
  1324.         bne    .NoQuit
  1325.         st    rh_oHostQuit(a5)            * Mark this host as quitting
  1326.  
  1327. .NoQuit:    move.l    d0,a0                    * Send the message
  1328.         bsr    _rh_AllocMsg
  1329.         beq    .Out
  1330.         move.l    d0,a1
  1331.         move.w    d2,rmsg_oType(a1)
  1332.  
  1333.         IFNE    MYDEBUG
  1334.         SFORBID
  1335.         DBUG    "Sending "
  1336.         PUSH    a0
  1337.         move.w    d2,d0
  1338.         bsr    _rh_IdentMsg
  1339.         DBUGIT    (a0)
  1340.         LEASTR    " to ",a0
  1341.         DBUGIT    (a0)
  1342.         POP    a0
  1343.         move.l    LN_NAME(a0),a2
  1344.         tst.l    a2
  1345.         bne    .NameOk
  1346.         LEASTR    "UNKNOWN PORT!",a2
  1347. .NameOk:    DBUGIT    (a2)
  1348.         LEASTR    "\n",a2
  1349.         DBUGIT    (a2)
  1350.         ENDC
  1351.  
  1352.         CALLEXE    PutMsg
  1353.         IFNE    MYDEBUG
  1354.         SPERMIT
  1355.         ENDC
  1356.         tst.w    d3                    * Do we need to Permit() ?
  1357.         beq    .Exit                    * No
  1358.         CALLLVO    Permit
  1359. .Exit:        moveq    #1,d0                    * Set success
  1360. .Out:        POP    d0-d3/a0-a1
  1361.         rts
  1362.  
  1363. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1364. *                                                *
  1365. *        Handle the RMSG_RAVEQUIT message and reply it with the success code set.    *
  1366. *                                                *
  1367. *        void rh_RaveQuit(struct Message *msg, struct RaveHost *host)            *
  1368. *                 a1              a5                    *
  1369. *                                                *
  1370. *        INPUTS    a1.l    Pointer to the message                        *
  1371. *            a5.l    Pointer to the host's RaveHost structure            *
  1372. *                                                *
  1373. *        FLAGS    EQ    Always set                            *
  1374. *                                                *
  1375. *        CHANGED    d0-d1/a0-a1/a6        (a6 = SysBase)                    *
  1376. *                                                *
  1377. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1378.  
  1379. _rh_RaveQuit:    DBUG    "Releasing the RaveScope.\n"
  1380.         DBUG    "Replying to RMSG_RAVEQUIT message.\n"
  1381.         clr.l    rh_oRaveBase(a5)            * Release it
  1382.         move.w    #RMSG_SUCCESS,rmsg_oResult(a1)        * And return success
  1383.         CALLEXE    ReplyMsg
  1384.         moveq    #0,d0
  1385.         rts
  1386.  
  1387. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1388. *                                                *
  1389. *        Remove given signal (d0) from the signal mask                    *
  1390. *                                                *
  1391. *        void rh_RemSig(BYTE signal, struct RaveHost *host)                *
  1392. *                   d0        a5                            *
  1393. *                                                *
  1394. *        INPUTS    d0.b    Signal number                            *
  1395. *            a5.l    Pointer to the host's RaveHost structure            *
  1396. *                                                *
  1397. *        OUTPUTS    none                                    *
  1398. *                                                *
  1399. *        CHANGED    d1                                    *
  1400. *                                                *
  1401. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1402.  
  1403. _rh_RemSig:    move.l    rh_oSigMask(a5),d1
  1404.         bclr.l    d0,d1
  1405.         move.l    d1,rh_oSigMask(a5)
  1406.         rts
  1407.  
  1408. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1409. *                                                *
  1410. *        Reset the configuration file to default values (but don't clear it)        *
  1411. *                                                *
  1412. *        void rh_ResetConfig(struct RaveHost *host)                    *
  1413. *                    a5                                *
  1414. *                                                *
  1415. *        INPUTS    a5.l    Pointer to the host's RaveHost structure            *
  1416. *                                                *
  1417. *        CHANGED    d0-d1/a0-a1                                *
  1418. *                                                *
  1419. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1420.  
  1421. _rh_ResetCfg:    DBUG    "Resetting config to default.\n"
  1422.         move.l    rh_oCfgPtr(a5),a1
  1423.         move.l    #RAVE_ID,hcfg_oID(a1)            * Reset ID
  1424.         move.l    #$FF0000FF,hcfg_oPopup(a1)        * Set popup related flags
  1425.         clr.b    hcfg_oRaveName(a1)            * Reset ravename
  1426.         rts
  1427.  
  1428. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1429. *                                                *
  1430. *        Send a message to the RaveScope (and wait for reply) IF WE HAVE IT.        *
  1431. *        Just exit Z set if we don't.                            *
  1432. *                                                *
  1433. *        void rh_SignalRave(UWORD msgclass, struct RaveHost *host)            *
  1434. *                   d0           a5                        *
  1435. *                                                *
  1436. *        INPUTS    d0.w    The message class, for example RMSG_PLYHALTED            *
  1437. *            a5.l    Pointer to the hosts RaveHost structure                *
  1438. *                                                *
  1439. *        OUTPUTS    none                                    *
  1440. *                                                *
  1441. *        FLAGS    GT    Message was sent and handled successfully.            *
  1442. *            MI    The message was sent, but was not successful.            *
  1443. *            EQ    The RaveScope is not present/wants to quit.            *
  1444. *                                                *
  1445. *        CHANGED    d0-d1/a0-a1/a6                                *
  1446. *                                                *
  1447. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1448.  
  1449. _rh_SignalRave:    DBUG    "** Entered rh_SignalRave.\n"
  1450.         tst.l    rh_oRaveBase(a5)            * Do we have the RaveScope?
  1451.         bne    _rh_WaitPutMsg                * Yes, send message
  1452.         rts                        * No, so don't try to msg it
  1453.  
  1454. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1455. *                                                *
  1456. *        Send a message to the RaveScope IF WE HAVE IT. Just exit Z set if we don't.    *
  1457. *                                                *
  1458. *        BOOL success = rh_TellRave(UWORD msgclass, struct RaveHost *host)        *
  1459. *        d0               d0           a5                    *
  1460. *                                                *
  1461. *        INPUTS    d0.w    The message class, for example RMSG_PLYHALTED            *
  1462. *            a5.l    Pointer to the hosts RaveHost structure                *
  1463. *                                                *
  1464. *        OUTPUTS    d0.w    TRUE or FALSE, corresponds to flags below.            *
  1465. *                                                *
  1466. *        FLAGS    EQ    The message could not be sent                    *
  1467. *            NE    The message was sent                        *
  1468. *                                                *
  1469. *        CHANGED    d0/a6                                    *
  1470. *                                                *
  1471. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1472.  
  1473. _rh_TellRave:    DBUG    "** Entered rh_TellRave.\n"
  1474.         tst.l    rh_oRaveBase(a5)            * Do we have the RaveScope?
  1475.         bne    _rh_PutMsg                * Yes, send message
  1476.         CLEAR    d0                    * No, so don't try to msg it
  1477.         rts
  1478.  
  1479. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1480. *                                                *
  1481. *        If the host has the RaveScope, find a channel header that can be updated and    *
  1482. *        check that it has enough channel-structures attached to it (allocate mem for    *
  1483. *        them if not) then call the supplied routine in a0, that must update the        *
  1484. *        channel structures. This routine will be called with a4=ptr to the channel    *
  1485. *        header and a5=the ravehost structure. It must return d0=1 if the channels    *
  1486. *        were updated, d0=0 if they were not and d0=-1 for serious error. It may not    *
  1487. *        change a4 or a5.                                *
  1488. *                                                *
  1489. *        LONG result=rh_UpdateChans(UWORD maxchans, LONG (*update_func), RaveHost *host)    *
  1490. *        d0               d1           a2            a5        *
  1491. *                                                *
  1492. *        INPUTS    d1.w    Make sure there's room for d1 channels, or if d1=0: don't care    *
  1493. *            a2.l    Pointer to the routine that updates the structure        *
  1494. *            a5.l    Pointer to the host's RaveHost structure            *
  1495. *                                                *
  1496. *        OUTPUTS    d0.l    1, 0 or -1, corresponds to flags below                *
  1497. *                                                *
  1498. *        FLAGS    GT    The channels were updated                    *
  1499. *            EQ    The channels were not updated                    *
  1500. *            MI    Serious error (out of mem etc), host should quit        *
  1501. *                                                *
  1502. *        CHANGED    d0-d7/a0-a4/a6                                *
  1503. *                                                *
  1504. *                                                *
  1505. *        Here's the specifications that your routine to update the channel        *
  1506. *        structures must conform to...                            *
  1507. *                                                *
  1508. *        LONG result = update_func(struct ScopeHeader *head, struct RaveHost *host)    *
  1509. *        d0              a4                a5                *
  1510. *                                                *
  1511. *        INPUTS    a4.l    Pointer to the scopeheader structure to update (always valid)    *
  1512. *            a5.l    Pointer to the host's RaveHost structure            *
  1513. *                                                *
  1514. *        OUTPUTS    d0.l     1 if you could update the channel structures,            *
  1515. *                 0 if you could not,                        *
  1516. *                -1 if a serious error occured.                    *
  1517. *                                                *
  1518. *        CHANGED    d0-d7/a0-a3/a6                                *
  1519. *                                                *
  1520. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1521.  
  1522. _rh_UpdateChans    tst.l    rh_oRaveBase(a5)            * Are we used by the RaveScope?
  1523.         beq    .Exit                    * No, exit.
  1524.         lea    rh_oChanHdrs(a5),a0            * Find a header to update
  1525.         moveq    #3-1,d0
  1526.         jsr    ([rh_oGet4Upd_f,a5])            * Get d0=header struct to update
  1527.         beq    .Exit                    * None available => exit
  1528.         move.l    d0,a4                    * a4=header to update
  1529.  
  1530.         tst.w    d1                    * Check if there's enough room?
  1531.         beq    .NoCheck                * No, always enough
  1532.         cmp.w    scph_oMaxChans(a4),d1            * Enough room?
  1533.         ble    .NoCheck                * Yes
  1534.         move.w    d1,d0                    * New #of channels
  1535.         moveq    #3-1,d1                    * Three sets of chanstructs
  1536.         lea    rh_oChanHdrs(a5),a0            * Pointer to channel headers
  1537.         jsr    ([rh_oMakeRoom_f,a5])            * Ensure there's room for all chans
  1538.         beq    .Error                    * It isn't, error!
  1539.  
  1540. .NoCheck:    jsr    (a2)                    * Update them!
  1541.         tst.l    d0                    * Succesful?
  1542.         beq    .Fail                    * No, just exit
  1543.         and.b    #~(SCPHF_INVALID!SCPHF_UPDATED),scph_oFlags(a4) * Not invalid/being upd
  1544.         tst.l    d0
  1545.         rts
  1546. .Exit:        CLEAR    d0
  1547.         rts
  1548. .Error:        moveq    #-1,d0
  1549.         rts
  1550. .Fail:        DBUG    "rh_UpateChans failed!\n"
  1551.         and.b    #~SCPHF_UPDATED,scph_oFlags(a4)        * Struct is no longer being updated
  1552.         tst.l    d0
  1553.         rts
  1554.  
  1555. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1556. *                                                *
  1557. *        TASK    Wait for the specified message to return. Unrelated messages will be    *
  1558. *            replied to with the failurecode set, unless it is RMSG_RAVEQUIT, in    *
  1559. *            which case this routine will exit EQ. The message we're waiting on will    *
  1560. *            be replied to with the successcode set.                    *
  1561. *                                                *
  1562. *        LONG result = rh_WaitMsg(UWORD msgclass, struct RaveHost *host)            *
  1563. *        d0             d0         a5                    *
  1564. *                                                *
  1565. *        INPUTS    d0.w    The message class, for example RMSG_HOSTQUIT            *
  1566. *            a5.l    Pointer to the hosts RaveHost structure                *
  1567. *                                                *
  1568. *        OUTPUTS    d0.l    1, -1 or 0, corresponds to flags below                *
  1569. *                                                *
  1570. *        FLAGS    GT    Message returned with its success code set            *
  1571. *            MI    Message returned with its failure code set            *
  1572. *            EQ    The RaveScope wants to quit.                    *
  1573. *                                                *
  1574. *        CHANGED    d0                                    *
  1575. *                                                *
  1576. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1577.  
  1578. _rh_WaitMsg:    PUSH    d1-d3/a0-a1/a6
  1579.         IFNE    MYDEBUG
  1580.         SFORBID
  1581.         DBUG    "** Entered rh_WaitMsg, want "        * Wait for reply to arrive
  1582.         bsr    _rh_IdentMsg
  1583.         DBUGIT    (a0)
  1584.         LEASTR    "\n",a0
  1585.         DBUGIT    (a0)
  1586.         SPERMIT
  1587.         ENDC
  1588.  
  1589.         move.w    d0,d2                    * d2 = message class to wait for
  1590. .W8Reply:    move.l    a5,a0                    * Wait until we get a message
  1591.         DBUG    "Going to sleep...\n"
  1592.         CALLEXE    WaitPort
  1593.         bsr    _rh_GetMsg
  1594.         beq    .W8Reply
  1595.         move.l    d0,a1
  1596.  
  1597.         cmp.w    d1,d2                    * Is it the one we're waiting on?
  1598.         beq    .GotReply
  1599.  
  1600.         btst    #RMSGB_FROMHOST,d1            * No. Is it from us?
  1601.         beq    .FromRave                * No, from the RaveScope
  1602.         bsr    _rh_FreeMsg                * Yes, free this message and
  1603.         bra    .W8Reply                * keep waiting
  1604. .FromRave:    cmp.w    #RMSG_RAVEQUIT,d1            * Is it a quit-message?
  1605.         bne    .NoQuit                    * No
  1606.         bsr    _rh_RaveQuit                * Yes, handle it
  1607.         bra    .Quit
  1608. .NoQuit:    bsr    _rh_FailMsg                * Fail all other messages
  1609.         bra    .W8Reply
  1610.  
  1611. .GotReply:    DBUG    "Got the msg we were waiting on.\n"
  1612.         move.w    rmsg_oResult(a1),d3            * Remember result
  1613.         btst    #RMSGB_FROMHOST,d1            * Was it from us?
  1614.         bne    .NoReply                * Yes, so don't reply to it
  1615.         moveq    #1,d3                    * No, from the RaveScope, set
  1616.         move.w    d1,d0                    * success and reply to it
  1617.         bsr    _rh_HandleMsg
  1618.         bra    .Exit
  1619.  
  1620. .NoReply:    bsr    _rh_FreeMsg                * Free our message.
  1621.         cmp.w    #RMSG_NEWHOST,d2            * Did we wait on the NEWHOST msg?
  1622.         bne    .Exit                    * No, exit
  1623.         tst.w    d3                    * Yes, did it succeed?
  1624.         bne    .NHostOk
  1625.         DBUG    "The RMSG_NEWHOST msg failed!\n"
  1626.         bra    .Fail
  1627.  
  1628. .NHostOk:    DBUG    "We got the RMSG_NEWHOST msg back OK. Now we must wait for RMSG_GRABRAVE!\n"
  1629.         move.w    #RMSG_GRABRAVE,d0            * Yes, so we must wait on the
  1630.         bsr    _rh_WaitMsg                * RMSG_GRABRAVE as well. Call it...
  1631.         beq    .Quit                    * Rave is quitting
  1632.  
  1633. .Exit:        tst.w    d3                    * Message successful?
  1634.         beq    .Fail                    * No
  1635.         DBUG    "Exiting rh_WaitMsg : SUCCESS\n"
  1636.         moveq    #1,d0                    * Yes
  1637. .Out:        POP    d1-d3/a0-a1/a6                * Report SUCCESS
  1638.         rts
  1639. .Fail:        DBUG    "Exiting rh_WaitMsg : FAILURE\n"
  1640.         moveq    #-1,d0                    * Report FAILURE
  1641.         bra    .Out
  1642. .Quit:        DBUG    "Exiting rh_WaitMsg : RAVEQUIT\n"
  1643.         CLEAR    d0                    * Report RAVE QUIT
  1644.         bra    .Out
  1645.  
  1646. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1647. *                                                *
  1648. *        TASK    PutMsg() a RaveMsg to the RaveScope and wait for reply.    Unrelated    *
  1649. *            messages will be replied to with the failurecode set, unless it        *
  1650. *            is RMSG_RAVEQUIT, in which case this routine will exit EQ.        *
  1651. *                                                *
  1652. *        LONG result = rh_WaitPutMsg(UWORD msgclass, struct RaveHost *host)        *
  1653. *        d0                d0            a5                    *
  1654. *                                                *
  1655. *        INPUTS    d0.w    The message class, for example RMSG_HOSTQUIT            *
  1656. *            a5.l    Pointer to the hosts RaveHost structure                *
  1657. *                                                *
  1658. *        OUTPUTS    d0.l    1, -1 or 0, corresponds to flags below                *
  1659. *                                                *
  1660. *        FLAGS    GT    Message was sent and handled successfully.            *
  1661. *            MI    The message was sent, but was not successful.            *
  1662. *            EQ    The RaveScope is not present/wants to quit.            *
  1663. *                                                *
  1664. *        CHANGED    d0-d1/a0-a1/a6                                *
  1665. *                                                *
  1666. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1667.  
  1668. _rh_WaitPutMsg:    PUSH    d0-d2/a0-a1
  1669.         move.w    d0,d2                    * d2 = message class
  1670.         bsr    _rh_PutMsg
  1671.         bne    .MsgOk
  1672.         DBUG    "Could not send the message!\n"
  1673.         CLEAR    d0
  1674.         bra    .Out
  1675. .MsgOk:        move.w    d2,d0
  1676.         bsr    _rh_WaitMsg
  1677.         IFNE    MYDEBUG
  1678.         beq    .RaveQuit
  1679.         bmi    .Failure
  1680.         DBUG    "Msg returned successfully!\n"
  1681.         moveq    #1,d0
  1682.         bra    .Out
  1683. .RaveQuit:    DBUG    "The RaveScope wants to quit!\n"
  1684.         CLEAR    d0
  1685.         bra    .Out
  1686. .Failure:    DBUG    "The msg was not successful!\n"
  1687.         moveq    #-1,d0
  1688.         ENDC
  1689. .Out:        POP    d0-d2/a0-a1
  1690.         rts
  1691.  
  1692.  
  1693.  
  1694.  
  1695.  
  1696.  
  1697.  
  1698.         * Private functions and data now follow *
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1706. *
  1707. *        Check for 020+
  1708.  
  1709. rh_Check020:    move.l    rh_oSysBase(a5),a0
  1710.         move.w    AttnFlags(a0),d0
  1711.         and.w    #AFF_68020,d0                * 020 or above present?
  1712.         bne    .Exit                    * Yes
  1713.         DBUG    "No 020 found!\n"
  1714.         CLEARA    a0                    * error message and exit.
  1715.         lea    rh_No020Req,a1
  1716.         CLEARA    a2
  1717.         CLEARA    a3
  1718.         CALLITN    EasyRequestArgs
  1719.         CLEAR    d0
  1720. .Exit:        rts
  1721.  
  1722.  
  1723. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1724. *
  1725. *        Create a message port
  1726.  
  1727. rh_MakeMsgPort:    DBUG    "** Entered rh_MakeMsgPort.\n"
  1728.         CALLEXE    Forbid
  1729.         DBUG    "Trying to find a portname that is not in use...\n"
  1730.  
  1731.         move.b    #'0'-1,rh_RHPortNmID            * Reset portname's ID
  1732. .FindName:    addq.b    #1,rh_RHPortNmID            * Increase ID
  1733.         lea    rh_RHPortName,a1            * Find a portname that is not
  1734.         CALLLVO    FindPort                * in use
  1735.         tst.l    d0                    * This one in use?
  1736.         bne    .FindName                * Yes, try next
  1737.         
  1738.         DBUG    "Creating message port...\n"        * Alloc signal
  1739.         bsr    _rh_AllocSig
  1740.         move.b    d0,rh_oSignal(a5)
  1741.         bmi    .Error
  1742.  
  1743.         move.b    d0,MP_SIGBIT(a5)
  1744.         move.l    #rh_RHPortName,LN_NAME(a5)        * Init the messageport
  1745.         move.b    #1,LN_PRI(a5)
  1746.         move.b    #NT_MSGPORT,LN_TYPE(a5)
  1747.         move.b    #PA_SIGNAL,MP_FLAGS(a5)
  1748.         move.l    rh_oThisTask(a5),MP_SIGTASK(a5)
  1749.         lea    rh_oMsgPort(a5),a1
  1750.         CALLLVO    AddPort
  1751.         CALLLVO    Permit
  1752.         st    rh_oMsgPortOk(a5)
  1753.         moveq    #1,d0
  1754.         rts
  1755.  
  1756. .Error:        CALLLVO    Permit
  1757.         ERRMSG    "Couldn't create messageport!"
  1758.         moveq    #0,d0
  1759.         rts
  1760.  
  1761.  
  1762. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1763. *
  1764. *        Free the message port
  1765.  
  1766. rh_FreeMsgPort:    DBUG    "** Entered rh_FreeMsgPort.\n"
  1767.         tst.b    rh_oMsgPortOk(a5)            * Message port created?
  1768.         beq    .Exit
  1769.         clr.b    rh_oMsgPortOk(a5)
  1770.  
  1771.         DBUG    "RemPort()ing...\n"            * Remove the port so that the
  1772.         lea    rh_oMsgPort(a5),a1            * RaveScope cannot find it again
  1773.         CALLEXE    RemPort
  1774.  
  1775.         tst.l    rh_oRaveBase(a5)            * Do we have the ravescope?
  1776.         beq    .NoQuitMsg                * No, don't send it quitmessage
  1777.         move.w    #RMSG_HOSTQUIT,d0            * Yes, tell it we're quitting
  1778.         bsr    _rh_WaitPutMsg
  1779.  
  1780. .NoQuitMsg:    DBUG    "Emptying our port from messages.\n"
  1781.         CALLEXE    Forbid                    * No more messages wanted
  1782. .EmptyPort:    bsr    _rh_GetMsg                * Try to get a message
  1783.         beq    .PortEmpty                * No more remains!
  1784.         move.l    d0,a1
  1785.         cmp.w    #RMSG_RAVEQUIT,d1            * RAVEQUIT message?
  1786.         bne    .FailMsg                * No, just return it
  1787.         bsr    _rh_RaveQuit                * Yes, handle it
  1788.         bra    .EmptyPort
  1789. .FailMsg:    btst    #RMSGB_FROMHOST,d1            * Not one of our messages?
  1790.         bne    .EmptyPort                * Yes, just ignore it
  1791.         bsr    _rh_FailMsg                * No, return it with FAILURE
  1792.         bra    .EmptyPort
  1793.  
  1794. .PortEmpty:    DBUG    "Port empty, freeing signal bit.\n"
  1795.         lea    rh_oSignal(a5),a0
  1796.         bra    _rh_FreeSig                * Free the related signal
  1797. .Exit:        rts
  1798.  
  1799. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1800. *
  1801. *        Free any allocated channel structures from the channel headers
  1802.  
  1803. rh_FreeChHds:    DBUG    "Freeing channel structures.\n"
  1804.         moveq    #3-1,d2
  1805.         lea    rh_oChanHdrs(a5),a2
  1806. .Free:        move.l    scph_oChannels(a2),d1
  1807.         beq    .Skip
  1808.         clr.l    scph_oChannels(a2)
  1809.         move.l    d1,a1
  1810.         CALLEXE    FreeVec
  1811. .Skip:        add.w    #scph_SIZEOF,a2
  1812.         dbra    d2,.Free
  1813.         rts
  1814.  
  1815. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1816. *
  1817. *        Free the RaveHost structure if this was allocated in rh_InitHost.
  1818.  
  1819. rh_FreeRHStr:    tst.b    rh_oFreeRHStr(a5)            * Must free it?
  1820.         beq    .Exit                    * No
  1821.         DBUG    "Freeing the RaveHost structure.\n"
  1822.         clr.b    rh_oFreeRHStr(a5)
  1823.         move.l    a5,a1
  1824.         CLEARA    a5
  1825.         JUMPEXE    FreeVec
  1826. .Exit:        rts
  1827.  
  1828. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1829. *
  1830. *        Free the memory allocated for the config (if any)
  1831.  
  1832. rh_FreeCfg:    move.l    rh_oCfgPtr(a5),d0
  1833.         beq    .Exit
  1834.         DBUG    "Freeing config memory.\n"
  1835.         clr.l    rh_oCfgPtr(a5)
  1836.         move.l    d0,a1
  1837.         JUMPEXE    FreeVec
  1838. .Exit:        rts
  1839.  
  1840. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1841. *
  1842. *        Error routines
  1843.  
  1844. rh_ErrOpenA2:    lea    rh_ErrSpace,a3                * Unable to open <name of object
  1845. .CopyErr:    move.b    (a2)+,(a3)+                * that failed supplied in a2>
  1846.         bne    .CopyErr
  1847.         SETERR    #rh_ErrOpenTxt
  1848.         CLEAR    d0
  1849.         rts
  1850.  
  1851. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1852. *
  1853. *        Debug routine that returns a pointer to the name of a message
  1854. *        INPUTS    d0    Type of the message
  1855. *        OUTPUTS    a0    Name of the message
  1856. *        CHANGED    a0
  1857.  
  1858.         IFNE    MYDEBUG                    
  1859.         XDEF    _rh_IdentMsg
  1860. _rh_IdentMsg:    PUSH    d0
  1861.         lea    .TypePtrs-2,a0
  1862. .FindIt:    add.w    #2,a0
  1863.         tst.w    (a0)
  1864.         beq    .Alien
  1865.         cmp.w    (a0)+,d0
  1866.         bne    .FindIt
  1867.         move.w    (a0),d0
  1868.         lea    .TypePtrs(pc,d0.w),a0
  1869.         POP    d0
  1870.         rts
  1871. .Alien:        LEASTR    "!!ALIEN MSG!!",a0
  1872.         POP    d0
  1873.         rts
  1874.  
  1875. .TypePtrs:    dc.w    RMSG_RAVEQUIT,.RAVEQUIT-.TypePtrs
  1876.         dc.w    RMSG_RAVEBUSY,.RAVEBUSY-.TypePtrs
  1877.         dc.w    RMSG_RAVEREADY,.RAVEREADY-.TypePtrs
  1878.         dc.w    RMSG_LEAVERAVE,.LEAVERAVE-.TypePtrs
  1879.         dc.w    RMSG_GRABRAVE,.GRABRAVE-.TypePtrs
  1880.         dc.w    RMSG_ADDPORTS,.ADDPORTS-.TypePtrs
  1881.         dc.w    RMSG_DELPORTS,.DELPORTS-.TypePtrs
  1882.         dc.w    RMSG_POKESTICK,.POKESTICK-.TypePtrs
  1883.         dc.w    RMSG_NEWHOST,.NEWHOST-.TypePtrs
  1884.         dc.w    RMSG_PLYHALTED,.PLYHALTED-.TypePtrs
  1885.         dc.w    RMSG_PLYACTIVE,.PLYACTIVE-.TypePtrs
  1886.         dc.w    RMSG_HOSTBUSY,.HOSTBUSY-.TypePtrs
  1887.         dc.w    RMSG_HOSTREADY,.HOSTREADY-.TypePtrs
  1888.         dc.w    RMSG_HOSTQUIT,.HOSTQUIT-.TypePtrs
  1889.         dc.w    RMSG_CLOSESCOPE,.CLOSESCOPE-.TypePtrs
  1890.         dc.w    RMSG_OPENSCOPE,.OPENSCOPE-.TypePtrs
  1891.         dc.w    RMSG_KILLRAVE,.KILLRAVE-.TypePtrs
  1892.         dc.w    RMSG_HIPHALTED,.HIPHALTED-.TypePtrs
  1893.         dc.w    RMSG_HIPACTIVE,.HIPACTIVE-.TypePtrs
  1894.         dc.w    RMSG_LOSTHIP,.LOSTHIP-.TypePtrs
  1895.         dc.w    RMSG_DOICONIFY,.DOICONIFY-.TypePtrs
  1896.         dc.w    RMSG_DEICONIFY,.DEICONIFY-.TypePtrs
  1897.         dc.w    RMSG_SAVECONFIG,.SAVECONFIG-.TypePtrs
  1898.         dc.w    0,0
  1899.  
  1900. .RAVEQUIT    dc.b    "RMSG_RAVEQUIT",0
  1901. .RAVEBUSY    dc.b    "RMSG_RAVEBUSY",0
  1902. .RAVEREADY    dc.b    "RMSG_RAVEREADY",0
  1903. .LEAVERAVE    dc.b    "RMSG_LEAVERAVE",0
  1904. .GRABRAVE    dc.b    "RMSG_GRABRAVE",0
  1905. .ADDPORTS    dc.b    "RMSG_ADDPORTS",0
  1906. .DELPORTS    dc.b    "RMSG_DELPORTS",0
  1907. .POKESTICK    dc.b    "RMSG_POKESTICK",0
  1908. .NEWHOST    dc.b    "RMSG_NEWHOST",0
  1909. .PLYHALTED    dc.b    "RMSG_PLYHALTED",0
  1910. .PLYACTIVE    dc.b    "RMSG_PLYACTIVE",0
  1911. .HOSTBUSY    dc.b    "RMSG_HOSTBUSY",0
  1912. .HOSTREADY    dc.b    "RMSG_HOSTREADY",0
  1913. .HOSTQUIT    dc.b    "RMSG_HOSTQUIT",0
  1914. .CLOSESCOPE    dc.b    "RMSG_CLOSESCOPE",0
  1915. .OPENSCOPE    dc.b    "RMSG_OPENSCOPE",0
  1916. .KILLRAVE    dc.b    "RMSG_KILLRAVE",0
  1917. .HIPHALTED    dc.b    "RMSG_HIPHALTED",0
  1918. .HIPACTIVE    dc.b    "RMSG_HIPACTIVE",0
  1919. .LOSTHIP    dc.b    "RMSG_LOSTHIP",0
  1920. .DOICONIFY:    dc.b    "RMSG_DOICONIFY",0
  1921. .DEICONIFY:    dc.b    "RMSG_DEICONIFY",0
  1922. .SAVECONFIG:    dc.b    "RMSG_SAVECONFIG",0
  1923.         ENDC
  1924.  
  1925.  
  1926. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1927. *
  1928. *        Window texts
  1929.  
  1930. rh_Version:    dc.b    "RaveScope 1.2 by Parsec 1998",0
  1931. rh_No020Txt:    dc.b    "Sorry, cannot start the RaveScope.",10,10
  1932.         dc.b    "This program requires a 68020 or better.",0
  1933.  
  1934. rh_RaveFailTxt:    dc.b    "The RaveScope could not be started.",10
  1935.         dc.b    "Maybe you have specified its path",10
  1936.         dc.b    "incorrectly.",0
  1937.  
  1938. rh_OkText:    dc.b    "  Ok  ",0
  1939. rh_OhText:    dc.b    "  Oh  ",0
  1940.  
  1941.         EVEN
  1942.  
  1943. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1944. *
  1945. *        TextRequesters
  1946.  
  1947. rh_No020Req:    dc.l    EasyStruct_SIZEOF            * size
  1948.         dc.l    0                    * Flags
  1949.         dc.l    rh_Version                * Title
  1950.         dc.l    rh_No020Txt                * TextFormat
  1951.         dc.l    rh_OhText                * GadgetFormat
  1952.  
  1953. rh_RaveFailReq:    dc.l    EasyStruct_SIZEOF            * size
  1954.         dc.l    0                    * Flags
  1955.         dc.l    rh_Version                * Title
  1956.         dc.l    rh_RaveFailTxt                * TextFormat
  1957.         dc.l    rh_OkText                * GadgetFormat
  1958.  
  1959. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1960. *
  1961. *        Tag lists
  1962.  
  1963. rh_ReqTags:    dc.l    RT_ReqPos,REQPOS_CENTERWIN,TAG_END    * Ravescope file request tags
  1964.  
  1965. rh_ExeTags:    dc.l    SYS_Asynch,-1                * Run asynchronos
  1966. rh_NilOutput:    dc.l    SYS_Output,0                * NIL: output file hd
  1967. rh_NilInput:    dc.l    SYS_Input,0                * NIL: input file hd
  1968.         dc.l    TAG_DONE
  1969.  
  1970. rh_ErrOpenTxt:    dc.b    "Unable to open "
  1971. rh_ErrSpace:    ds.b    20
  1972.  
  1973. rh_RHPortName:    dc.b    'RaveScope-Host.'            * The hosts msgports are named
  1974. rh_RHPortNmID:    dc.b    '0',0                    * RaveScope-Host.x (x=ID, 0 & up)
  1975. rh_RSPortName:    dc.b    'RaveScope',0
  1976. rh_NilName:    dc.b    'NIL:',0
  1977. rh_AskFileTxt:    dc.b    "Select the RaveScope executable...",0    * Ravescope exe file select text
  1978. rh_DRCfgKey:    dc.b    " ",0
  1979.  
  1980.  
  1981. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1982. *
  1983. *
  1984.         SECTION RaveHostBSS,BSS
  1985. *
  1986. *
  1987.  
  1988. rh_FileName:    ds.b    108                    * RaveScope's filename, 4 reqtools
  1989.  
  1990.  
  1991.  
  1992.